package com.lj.demo.orderService.controller;


import com.lj.demo.commonutils.R;
import com.lj.demo.orderService.service.TPayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author liujiang
 * @since 2021-01-08
 */
@RestController
@RequestMapping("/orderService/log")
@CrossOrigin
public class TPayLogController {

    @Autowired
    private TPayLogService payLogService;

    //生成二维码
    @GetMapping("/crateNative/{orderNo}")
    public R creatNative(@PathVariable String orderNo){
        Map map = payLogService.creatNative(orderNo);
        return R.ok().data(map);
    }

    //获取订单支付状态
    @GetMapping("/queryPayStatus/{orderNo}")
    public R queryPayStatus(@PathVariable String orderNo){
        //调用查询接口
        Map<String,String> map = payLogService.queryPayStatus(orderNo);
        if (map == null){//出错
            return R.error().message("支付出错");
        }
        if (map.get("trade_state").equals("SUCCESS")){//如果成功
            //更改订单状态
            payLogService.updateOrserStatus(map);
            return R.ok().message("支付成功");

        }
        return R.ok().code(25000).message("支付中");
    }
}

